<template>
  <div>
    <a-card>
      <div class="header__view">
        <a-button @click="addHandler" type="primary" icon="plus">新增</a-button>
      </div>
      <Table ref="STableRef" @formHandler="formHandler" @authHandler="authHandler"></Table>
    </a-card>
    <Form ref="FormRef" v-model="formVisible" :modelTitle="modelTitle" @confirmHandle="confirmHandle"></Form>
    <AuthForm ref="AuthFormRef" v-model="authVisible" :title="modelTitle"></AuthForm>
  </div>
</template>

<script>
import Table from './modules/table'
import Form from './modules/form'
import AuthForm from './modules/authForm'

export default {
  name: 'system-rolesManage',
  components: {
    Table,
    Form,
    AuthForm
  },
  data() {
    return {
      formVisible: false,
      authVisible: false,
      modelTitle: '添加'
    }
  },
  mounted() {},
  methods: {
    formHandler(e) {
      if (e) {
        // 编辑
        this.modelTitle = '编辑'
        this.$refs['FormRef'].initForm(e)
      } else {
        // 新增
        this.modelTitle = '添加'
        this.formVisible = true
      }
    },
    addHandler() {
      this.formVisible = true
    },
    confirmHandle(e) {
      let status = false
      if (e) status = true
      this.$refs['STableRef'].restList({}, status)
    },
    authHandler(e) {
      this.authVisible = true
      this.$refs['AuthFormRef'].initForm(e.id, e.name)
    }
  }
}
</script>

<style lang="less" scoped>
.header__view {
  margin-bottom: 20px;
}
</style>
